package com.fram.service.admin.botany.impl;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fram.bean.admin.botany.request.BotanyCategorySearchRequest;
import com.fram.bean.admin.botany.response.BotanyCategorySearchResponse;
import com.fram.common.canstant.ErrCode;
import com.fram.common.exception.ProAffairException;
import com.fram.common.exception.ProRunTimeException;
import com.fram.entity.BotanyCategory;
import com.fram.mapper.BotanyCategoryMapper;
import com.fram.service.admin.botany.BotanyCategoryService;

/**
 * @作者： 陳曉鬆 @时间： 2020年7月2日 - 下午3:16:07 @description：->
 */
@Service("botanyCategoryService")
public class BotanyCategoryServiceImpl implements BotanyCategoryService {

	@Autowired
	private BotanyCategoryMapper botanyCategoryMapper;

	@Override
	@Transactional
	public void insertCategory(BotanyCategory request) throws ProAffairException {
		if (botanyCategoryMapper.insertSelective(request) == 0) {
			throw new ProRunTimeException(ErrCode.FAIL.getReturnCode(), ErrCode.FAIL.getReturnMsg());
		}
	}

	@Override
	@Transactional
	public List<BotanyCategorySearchResponse> list(BotanyCategorySearchRequest request) throws ProAffairException {
		if (request.getLevel() == null) {
			request.setLevel(1);
		}
		List<BotanyCategorySearchResponse> list = botanyCategoryMapper.list(request);
		if (list == null || list.size() == 0) {
			throw new ProRunTimeException(ErrCode.NO_DATA.getReturnCode(), ErrCode.NO_DATA.getReturnMsg());
		}
		return list;
	}

}
